package de.se2.sharebox.classes;

import java.util.Vector;


public class Log
{
	Vector<LogEntry> logEntrys = new Vector<LogEntry>();
	private static Log instance = null;


	private Log()
	{

	}

	public static Log getInstance()
	{
		if (instance == null)
			instance = new Log();

		return instance;
	}

	public LogEntry[] getEntrysBySource(String source)
	{
		LogEntry[] ret = new LogEntry[logEntrys.size()];
		Vector<LogEntry> tmp = new Vector<LogEntry>();

		for (int i = 0 ; i < logEntrys.size() ; i++)
		{
			if (source == null || logEntrys.get(i).getSource().equals(source))
			{
				tmp.add(logEntrys.get(i));
			}
		}

		tmp.copyInto(ret);
		return ret;
	}

	public boolean addEntry(String source, String message)
	{
		return logEntrys.add(new LogEntry(source, message));
	}
}
